(function(YuXi){
	var recursionSource={};
	//去掉重复值
	recursionSource.unique=function(arr) {
		    var result = [], hash = {};
		    for (var i = 0, elem; (elem = arr[i]) != null; i++) {
		        if (!hash[elem]) {
		            result.push(elem);
		            hash[elem] = true;
		        }
   	 }
   	 return result;
	}

	recursionSource.flagsource=function(souceid,flag,object){

		var rsArray=[];
		var superid="";//上层渠道
		var x="";
		var y=[];
		if(flag==2)
		{
			
			y=requestFenkou();
		
		}
		else
		{

			y=requestSource();//请求渠道
		}
		
		setTimeout(function(){
			return y;
		},200);
		//向后台请求分口信息
		function requestFenkou()
		{	

			souceid=parseInt(souceid);
		
			for(var j=0;j<object.length;j++)
			{
				if(object[j].id==souceid)
				{
					superid=object[j].superId;
			
				}
			}
			mainrecurFenkou(superid,object);			
			
			
			
		}
		//向后台请求渠道信息
		function requestSource()
		{	
			
			
			souceid=parseInt(souceid);
			
			for(var j=0;j<object.length;j++)
			{
				if(object[j].id==souceid)
				{
					superid=object[j].superId;
			
				}
			}
			mainrecur(superid,object);			
			
			
			
		}
		//--------------
		function mainrecurFenkou(superid,souceobj)
		{
			
		

			for(var i=0;i<object.length;i++)
			{
				if(parseInt(object[i].id)==parseInt(superid))
				{   

					rsArray.push(object[i].portName);	
												
					mainrecurFenkou(object[i].superid,souceobj);
					
				}
				
			}
			

		}

		function mainrecur(superid,souceobj)
		{
		
			if(superid==0||superid=="0")
			{	
			
				return false;
			}

			
			for(var i=0;i<object.length;i++)
			{
				if(parseInt(object[i].id)==parseInt(superid))
				{   
				
					rsArray.push(object[i].name);	
												
					mainrecur(object[i].superId,souceobj);
					
				}
			}
			

		}

		return rsArray;










	}


	//根据选中渠道的superid递归渠道上级
	recursionSource.get=function(souceid,flag){
		var object={};
		var rsArray=[];
		var superid="";//上层渠道
		var x="";
		if(flag=="1")
		{
			
			y=requestFenkou();
		}
		else
		{
			y=requestSource();//请求渠道
		}
		
		setTimeout(function(){
			return y;
		},200);
		//向后台请求分口信息
		function requestFenkou()
		{	
			
			var url="getAllInformationPort.do";//渠道地址
			var data={};
			data=YuXi.util.getAsynCache(url,"null",function(data){
			object=data.object;
			souceid=parseInt(souceid);
			superid=souceid;
			
			mainrecurFenkou(superid,object);			
			},function(){});//请求数据
			
			
		}
		//向后台请求渠道信息
		function requestSource()
		{	
			
			var url="getAllInfomationSource.do";//渠道地址
			var data={};
			data=YuXi.util.getAsynCache(url,"null",function(data){
			object=data.object;
			souceid=parseInt(souceid);
			
			for(var j=0;j<object.length;j++)
			{
				if(object[j].id==souceid)
				{
					superid=object[j].superId;
			
				}
			}
			mainrecur(superid,object);			
			},function(){});//请求数据
			
			
		}
		//--------------
		function mainrecurFenkou(id,souceobj)
		{
			
			

			for(var i=0;i<object.length;i++)
			{
				if(parseInt(object[i].superId)==parseInt(id))
				{   
					rsArray.push(object[i].id);	
												
					mainrecurFenkou(object[i].id,souceobj);
					
				}
				
			}
			

		}

		function mainrecur(superid,souceobj)
		{
			
			if(superid==0||superid=="0")
			{	
			
				return false;
			}

			
			for(var i=0;i<object.length;i++)
			{
				if(parseInt(object[i].id)==parseInt(superid))
				{   
					rsArray.push(object[i].id);	
												
					mainrecur(object[i].superId,souceobj);
					
				}
			}
			

		}
		
		return rsArray.join(",");
	}
	YuXi.recursionSource=recursionSource;
})(window.YuXi)
